package com.zzr.zzrbackend.service.Impl;


import com.zzr.zzrbackend.config.JwtInterceptor;
import com.zzr.zzrbackend.mapper.*;
import com.zzr.zzrbackend.pojo.domain.*;
import com.zzr.zzrbackend.pojo.dto.CommonResult;
import com.zzr.zzrbackend.pojo.dto.param.DisabuseParam;
import com.zzr.zzrbackend.pojo.dto.param.DisabuseParentParam;
import com.zzr.zzrbackend.pojo.dto.param.DisabuseVolunteerParam;
import com.zzr.zzrbackend.pojo.dto.param.VolunteerScoreParam;
import com.zzr.zzrbackend.pojo.dto.result.*;
import com.zzr.zzrbackend.service.DisabuseService;
import com.zzr.zzrbackend.util.TokenUtils;
import io.jsonwebtoken.Claims;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DisabuseServiceImpl implements DisabuseService {

    @Resource
    private DisabuseRecordMapper disabuseRecordMapper;
    @Resource
    private JwtInterceptor jwtInterceptor;
    @Resource
    private UserMapper userMapper;
    @Resource
    private RelationMapper relationMapper;
    @Resource
    private SituationRecordVolunteerMapper situationRecordVolunteerMapper;
    @Resource
    private SituationRecordImageMergeMapper situationRecordImageMergeMapper;
    @Resource
    private SituationRecordParentMapper situationRecordParentMapper;
    @Resource
    private LiveGroupChatRoomMapper liveGroupChatRoomMapper;
    @Resource
    private UserInfoMapper userInfoMapper;
    @Resource
    private VolunteerSortMapper volunteerSortMapper;
    @Resource
    HttpServletRequest request;
    @Resource
    private VolunteerScoreMapper volunteerScoreMapper;

    @Override
    public CommonResult<DisabuseListResult> getDisabuseList(HttpServletRequest request) {
        Integer userId = jwtInterceptor.getUserId(request);
        Integer permission = userMapper.selectPermissionByUserId(userId);
        List<DisabuseResult> disabuseResultList = new ArrayList<>();
        if (permission == 1) {
            //如果是小孩
            List<DisabuseRecord> disabuseListByChildId = disabuseRecordMapper.selectDisabuseListByChildId(userId);
            for (DisabuseRecord temp : disabuseListByChildId) {
                //加入list中
                disabuseResultList.add(setDisabuseResult(temp));
            }
        } else if (permission == 2) {
            //如果是家长
            //先判断他的孩子是谁
            List<Integer> childIdList = relationMapper.selectChildIdByParentId(userId);
            for (Integer childId : childIdList) {
                List<DisabuseRecord> disabuseListByChildId = disabuseRecordMapper.selectDisabuseListByChildId(childId);
                for (DisabuseRecord temp : disabuseListByChildId) {
                    //加入list中
                    disabuseResultList.add(setDisabuseResult(temp));
                }
            }
        } else if (permission == 3) {
            //如果是志愿者
            List<DisabuseRecord> disabuseListByChildId = disabuseRecordMapper.selectAllDisabuseList();
            for (DisabuseRecord temp : disabuseListByChildId) {
                //加入list中
                disabuseResultList.add(setDisabuseResult(temp));
            }
        }
//        else if (permission == 3) {
//            //如果是志愿者 展示所有求助
////            List<DisabuseRecord> allDisabuseList = disabuseRecordMapper.selectAllDisabuseList();
//
//            RecommendVolunteerType recommendVolunteerType = new RecommendVolunteerType();
//            List<String> snList = recommendVolunteerType.getRecommend(userId);
//            if(snList == null){
//                return CommonResult.fail("数据库异常");
//            }
//            List<DisabuseRecord> recommendDisabuseList = new ArrayList<>();
//            List<DisabuseRecord> disabuseAllRecordList = disabuseRecordMapper.selectAllAcceptByVolunteerId(userId);
//            for(String s: snList){
//                int type = Integer.parseInt(s.trim());
//
//                List<DisabuseRecord> disabuseRecordList = disabuseRecordMapper.selectByType(type);
//                if(disabuseRecordList.size()!=0){
//                    recommendDisabuseList.addAll(disabuseRecordList);
//                }
//            }
//            recommendDisabuseList.addAll(disabuseAllRecordList);
//
////            List<DisabuseResult> tempDisabuseResultList = new ArrayList<>();
//            for (DisabuseRecord temp : recommendDisabuseList) {
//                //加入list中
//                DisabuseResult disabuseResult = new DisabuseResult();
//                disabuseResult.setId(temp.getId());
//                disabuseResult.setName(userMapper.selectUserNameById(temp.getChildId()));
//                disabuseResult.setChildId(temp.getChildId());
//                disabuseResult.setQuestion(temp.getQuestion());
//                disabuseResult.setType(String.valueOf(temp.getType()));
//                //处理solve_type
//                if (temp.getSolveType() == 1) {
//                    disabuseResult.setSolveType("线下");
//                } else if (temp.getSolveType() == 2) {
//                    disabuseResult.setSolveType("视频");
//                } else if (temp.getSolveType() == 3) {
//                    disabuseResult.setSolveType("语音");
//                } else if (temp.getSolveType() == 4) {
//                    disabuseResult.setSolveType("文字");
//                }
//                //处理是否匿名
//                disabuseResult.setIsAnonymous(temp.getIsAnonymous());
//                //处理是否立即解决
//                disabuseResult.setIsNowSolve(temp.getIsNowSolve());
//                //处理是否完成
//                disabuseResult.setIsFinish(temp.getIsFinish());
//                disabuseResult.setTime(temp.getTime());
//                disabuseResult.setIsAccept(temp.getIsAccept());
//                if (disabuseResult.getIsAnonymous() == 1) {
//                    disabuseResult.setName("匿名");
//                }
//                disabuseResultList.add(disabuseResult);
//            }
//
//
//        }
        DisabuseListResult disabuseListResult = new DisabuseListResult();
        disabuseListResult.setDisabuseResultList(disabuseResultList);
        return CommonResult.success(disabuseListResult);
    }

    @Override
    public CommonResult<DisabuseResult> getDisabuseDetail(HttpServletRequest request, Integer disabuseId) {
        Integer userId = jwtInterceptor.getUserId(request);
        if (userId == null) return CommonResult.fail_login();
        //获取Disabuse
        DisabuseRecord disabuseRecord = disabuseRecordMapper.selectDisabuseRecordByDisabuseId(disabuseId);
        //初始化返回
        DisabuseResult disabuseResult = setDisabuseResult(disabuseRecord);
        Integer roomId = liveGroupChatRoomMapper.selectIdByDisabuseId(disabuseId);
        disabuseResult.setGroupLiveChatRoomId(roomId);
        try {
            disabuseResult.setGroupLiveChatRoomName(liveGroupChatRoomMapper.selectNameByDisabuseId(disabuseId));
        } catch (Exception e) {
            disabuseResult.setGroupLiveChatRoomName("异常群聊");
            System.out.println(e.getMessage());
        }
        //兼容老版本群聊
        if (disabuseResult.getGroupLiveChatRoomName() == null) {
            disabuseResult.setGroupLiveChatRoomName("id为" + disabuseId + "的老版本群聊");
        }
        return CommonResult.success(disabuseResult);
    }

    @Override
    public CommonResult<SituationVolunteerRecordResult> getDisabuseVolunteerDetail(HttpServletRequest request,
                                                                                   Integer disabuseId, Integer order) {
        //进入返回记录处理阶段
        SituationRecordVolunteer situationRecordVolunteer =
                situationRecordVolunteerMapper.selectSituationRecord(disabuseId, order);
        //初始化返回类
        SituationVolunteerRecordResult situationVolunteerRecordResult = new SituationVolunteerRecordResult();
        situationVolunteerRecordResult.setVolunteerId(situationRecordVolunteer.getVolunteerId());
        situationVolunteerRecordResult.setOther(situationRecordVolunteer.getOther());
        situationVolunteerRecordResult.setEmotionalState(situationRecordVolunteer.getEmotionalState());
        situationVolunteerRecordResult.setSuggestion(situationRecordVolunteer.getSuggestion());
        situationVolunteerRecordResult.setOrder(situationRecordVolunteer.getOrder());
        //载入图片链接
        List<String> imageUrls =
                situationRecordImageMergeMapper.selectSituationRecordImage(situationRecordVolunteer.getId());
        situationVolunteerRecordResult.setImageUrlList(imageUrls);
        //载入返回类
        return CommonResult.success(situationVolunteerRecordResult);
    }

    @Override
    public CommonResult<NoData> getDisabuseVolunteerId(HttpServletRequest request, Integer disabuseId) {
        Integer userId = jwtInterceptor.getUserId(request);
        Integer permission = userMapper.selectPermissionByUserId(userId);
        if(permission == 1){
            Integer integers = disabuseRecordMapper.selectVolunteerIdByChildIdAndDisabuseId(userId,disabuseId);
            if(integers == null){
                return CommonResult.success("-1");
            }else {
                return CommonResult.success(String.valueOf(integers));
            }
        }else {
            return CommonResult.success(String.valueOf(-1));
        }
    }

    @Override
    public CommonResult<SituationRecordParent> getDisabuseParentDetail(HttpServletRequest request, Integer disabuseId
            , Integer order) {
        //进入返回记录处理阶段
        SituationRecordParent situationRecordParent = situationRecordParentMapper.selectSituationRecord(disabuseId,
                order);
        return CommonResult.success(situationRecordParent);
    }

    @Override
    public CommonResult<NoData> setDisabuse(HttpServletRequest request, DisabuseParam disabuseParam) {
        //鉴权
        Integer userId = jwtInterceptor.getUserId(request);
        Integer permission = userMapper.selectPermissionByUserId(userId);
        if (permission == 1) {
            //如果是小孩
            DisabuseRecord disabuseRecord = new DisabuseRecord();
            disabuseRecord.setChildId(userId);
            //装配DisabuseRecord表
            disabuseRecord.setType(disabuseParam.getType());
            disabuseRecord.setQuestion(disabuseParam.getQuestion());
            disabuseRecord.setSolveType(disabuseParam.getSolveType());
            disabuseRecord.setIsAnonymous(disabuseParam.getIsAnonymous());
            disabuseRecord.setIsNowSolve(disabuseParam.getIsNowSolve());
            disabuseRecord.setIsFinish(0);
            disabuseRecord.setTime(System.currentTimeMillis() / 1000);
            disabuseRecordMapper.insert(disabuseRecord);
            //初始化三方聊天室
            Long time = System.currentTimeMillis() / 1000;
            Integer parentId = relationMapper.selectParentIdByChildId(userId);
            liveGroupChatRoomMapper.init(disabuseRecord.getId(), userId, parentId, time);
            liveGroupChatRoomMapper.setNameByDisabuseId(disabuseRecord.getId(), "id为" + disabuseRecord.getId() +
                    "的解惑群");
            return CommonResult.success();
        } else {
            //不是小孩则失败
            return CommonResult.userAuthError();
        }
    }

    @Override
    public CommonResult<NoData> setParentDisabuse(HttpServletRequest request,
                                                  DisabuseParentParam disabuseParentParam) {
        //鉴权
        Integer userId = jwtInterceptor.getUserId(request);
        Integer permission = userMapper.selectPermissionByUserId(userId);
        if (permission == 2) {
            SituationRecordParent record =
                    situationRecordParentMapper.selectSituationRecord(disabuseParentParam.getDisabuseId(),
                            disabuseParentParam.getOrder());
            SituationRecordParent situationRecordParent = new SituationRecordParent();
            situationRecordParent.setDisabuseId(disabuseParentParam.getDisabuseId());
            situationRecordParent.setParentId(userId);
            situationRecordParent.setOrder(disabuseParentParam.getOrder());
            situationRecordParent.setAdvise(disabuseParentParam.getAdvise());
            situationRecordParent.setOther(disabuseParentParam.getOther());
            if (record == null) {
                situationRecordParentMapper.insert(situationRecordParent);
            } else {
                situationRecordParent.setId(record.getId());
                situationRecordParentMapper.update(situationRecordParent);
            }
            return CommonResult.success();
        } else {
            //不是家长则失败
            return CommonResult.userAuthError();
        }
    }

    @Override
    public CommonResult<NoData> setVolunteerDisabuse(HttpServletRequest request,
                                                     DisabuseVolunteerParam disabuseVolunteerParam) {
        //鉴权
        Integer userId = jwtInterceptor.getUserId(request);
        Integer permission = userMapper.selectPermissionByUserId(userId);
        if (permission == 3) {
            //如果是志愿者
            SituationRecordVolunteer record =
                    situationRecordVolunteerMapper.selectSituationRecord(disabuseVolunteerParam.getDisabuseId(),
                            disabuseVolunteerParam.getOrder());
            SituationRecordVolunteer situationRecordVolunteer = new SituationRecordVolunteer();
            situationRecordVolunteer.setDisabuseId(disabuseVolunteerParam.getDisabuseId());
            situationRecordVolunteer.setVolunteerId(userId);
            situationRecordVolunteer.setOrder(disabuseVolunteerParam.getOrder());
            situationRecordVolunteer.setEmotionalState(disabuseVolunteerParam.getEmotionState());
            situationRecordVolunteer.setSuggestion(disabuseVolunteerParam.getSuggestion());
            situationRecordVolunteer.setOther(disabuseVolunteerParam.getOther());
            if (record == null) {
                situationRecordVolunteerMapper.insert(situationRecordVolunteer);
            } else {
                situationRecordVolunteer.setId(record.getId());
                situationRecordVolunteerMapper.update(situationRecordVolunteer);
            }
            List<SituationRecordImageMerge> imageMerges =
                    situationRecordImageMergeMapper.selectAll(situationRecordVolunteer.getId());
            if (imageMerges.size() != 0) {
                situationRecordImageMergeMapper.deleteBySituationRecordId(situationRecordVolunteer.getId());
            }
            //插入图片
            for (String url : disabuseVolunteerParam.getImageList()) {
                SituationRecordImageMerge situationRecordImageMerge = new SituationRecordImageMerge();
                situationRecordImageMerge.setSituationRecordId(situationRecordVolunteer.getId());
                situationRecordImageMerge.setImageUrl(url);
                situationRecordImageMergeMapper.insert(situationRecordImageMerge);
            }
        } else {
            //不是志愿者则失败
            return CommonResult.userAuthError();
        }
        return CommonResult.success();
    }

    @Override
    public CommonResult<DisabuseCountResult> getDisabuseCount(HttpServletRequest request, Integer disabuseId) {
        DisabuseCountResult disabuseCountResult = new DisabuseCountResult();
        disabuseCountResult.setParentCount(situationRecordParentMapper.selectCountByDisabuseId(disabuseId));
        disabuseCountResult.setVolunteerCount(situationRecordVolunteerMapper.selectCountByDisabuseId(disabuseId));
        return CommonResult.success(disabuseCountResult);
    }

    @Override
    public CommonResult<SingleDisabuseCountNum> getSingleDisabuseCount(HttpServletRequest request, Integer disabuseId
            , Integer type) {
        Claims claims = TokenUtils.getClaimsFromJwt(request.getHeader("token"));
        Integer permission = (Integer) claims.get("permission");
        Map<String, String> map = new HashMap<>();
        if (permission == 2 && type == 1) {
            //家长端
            Integer count = situationRecordParentMapper.selectCountByDisabuseId(disabuseId);
            for (int i = 1; i <= count; i++) {
                String text = "{ value: " + i + ", text: " + "第" + i + "次建议 }";
                map.put("value", text);
            }
        } else if (permission == 3 && type == 2) {
            //志愿者端
            Integer count = situationRecordVolunteerMapper.selectCountByDisabuseId(disabuseId);
            for (int i = 1; i <= count; i++) {
                String text = "{ value: " + i + ", text: " + "第" + i + "次建议 }";
                map.put("value", text);
            }
        } else {
            return CommonResult.userAuthError();
        }
        SingleDisabuseCountNum singleDisabuseCountNum = new SingleDisabuseCountNum();
        singleDisabuseCountNum.setDisabuseCount(map);
        return CommonResult.success(singleDisabuseCountNum);
    }

    @Override
    public CommonResult<PersonalInformationResult> getPersonalInformation(HttpServletRequest request,
                                                                          Integer disabuseId) {
        DisabuseRecord disabuseRecord = disabuseRecordMapper.selectDisabuseRecordByDisabuseId(disabuseId);
        if (disabuseRecord.getIsAnonymous() != 0) {
            return CommonResult.fail("该解惑为匿名解惑，无法获取信息");
        }
        //初始化返回
        PersonalInformationResult personalInformationResult = new PersonalInformationResult();

        LiveGroupChatRoom liveGroupChatRoom = liveGroupChatRoomMapper.selectByDisabuseId(disabuseId);
        //置入小孩信息
        if (null != liveGroupChatRoom && null != liveGroupChatRoom.getChildId()) {
            UserInfo userInfo = userInfoMapper.selectByPrimaryKey(liveGroupChatRoom.getChildId());
            ChildProfileResult childProfileResult = new ChildProfileResult();
            childProfileResult.setUserName(userInfo.getUserName());
            childProfileResult.setGender(userInfo.getGender());
            childProfileResult.setNativePlace(userInfo.getNativePlace());
            childProfileResult.setAge(userInfo.getAge());
            childProfileResult.setGrade(userInfo.getGrade());
            childProfileResult.setSign(userInfo.getSign());
            childProfileResult.setHeadPicUrl(userInfo.getHeadPicUrl());
            personalInformationResult.setChildProfileResult(childProfileResult);
        }
        //置入家长信息
        if (null != liveGroupChatRoom && null != liveGroupChatRoom.getParentId()) {
            UserInfo userInfo = userInfoMapper.selectByPrimaryKey(liveGroupChatRoom.getParentId());
            User user = userMapper.selectById(liveGroupChatRoom.getParentId());
            ParentProfileResult parentProfileResult = new ParentProfileResult();
            parentProfileResult.setUserName(userInfo.getUserName());
            parentProfileResult.setGender(userInfo.getGender());
            parentProfileResult.setRelation(userInfo.getRelation());
            parentProfileResult.setNativePlace(userInfo.getNativePlace());
            parentProfileResult.setAge(userInfo.getAge());
            parentProfileResult.setPhone(user.getPhone());
            parentProfileResult.setWorkAddress(userInfo.getWorkAddress());
            parentProfileResult.setHomeSituation(userInfo.getHomeSituation());
            parentProfileResult.setSoftwareSituation(userInfo.getSoftwareSituation());
            parentProfileResult.setRemarkChild(userInfo.getRemarkChild());
            parentProfileResult.setRemarkVolunteer(userInfo.getRemarkVolunteer());
            parentProfileResult.setHeadPicUrl(userInfo.getHeadPicUrl());
            personalInformationResult.setParentProfileResult(parentProfileResult);
        }
        return CommonResult.success(personalInformationResult);
    }

    @Override
    public CommonResult<NoData> setSolve(HttpServletRequest request, Integer disabuseId) {
        Claims claims = TokenUtils.getClaimsFromJwt(request.getHeader("token"));
        Integer userId = (Integer) claims.get("id");
        Integer permission = (Integer) claims.get("permission");
        if (permission != 3) return CommonResult.userAuthError("用户未有权限");
        disabuseRecordMapper.setAcceptSolve(disabuseId, userId);

        DisabuseRecord disabuseRecord = disabuseRecordMapper.selectDisabuseRecordByDisabuseId(disabuseId);
        if(disabuseRecord==null){
            return CommonResult.fail("数据库异常");
        }

        if(disabuseRecord.getType()==1){
         volunteerSortMapper.setCount1(userId);
        }
        if(disabuseRecord.getType()==2){
            volunteerSortMapper.setCount2(userId);
        }
        if(disabuseRecord.getType()==3){
            volunteerSortMapper.setCount3(userId);
        }
        if(disabuseRecord.getType()==4){
            volunteerSortMapper.setCount4(userId);
        }
        if(disabuseRecord.getType()==5){
            volunteerSortMapper.setCount5(userId);
        }
        if(disabuseRecord.getType()==6){
            volunteerSortMapper.setCount6(userId);
        }
        if(disabuseRecord.getType()==7){
            volunteerSortMapper.setCount7(userId);
        }

        return CommonResult.success();
    }

    @Override
    public CommonResult<NoData> setAcceptSolve(HttpServletRequest request, Integer disabuseId) {
        Claims claims = TokenUtils.getClaimsFromJwt(request.getHeader("token"));
        Integer userId = (Integer) claims.get("id");
        Integer permission = (Integer) claims.get("permission");
        if (permission != 1) return CommonResult.userAuthError("用户未有权限");
        disabuseRecordMapper.setFinish(disabuseId, userId);
        return CommonResult.success();
    }

    @Override
    public CommonResult<NoData> setAcceptId(HttpServletRequest request, Integer disabuseId) {
        Claims claims = TokenUtils.getClaimsFromJwt(request.getHeader("token"));
        Integer userId = (Integer) claims.get("id");
        Integer permission = (Integer) claims.get("permission");
        if (permission != 3) return CommonResult.userAuthError("用户未有权限");
        if (disabuseRecordMapper.selectAcceptIdByDisabuseId(disabuseId) == 0) {
            disabuseRecordMapper.setSolve(disabuseId, userId);
            disabuseRecordMapper.setAcceptId(disabuseId, userId);
            liveGroupChatRoomMapper.setVolunteerId(disabuseId, userId);
        } else {
            return CommonResult.fail("该解惑已绑定志愿者，无法完成操作");
        }
        return CommonResult.success();
    }

    @Override
    public CommonResult<NoData> getNotSolveDisabuseNum(HttpServletRequest request) {
        Claims claims = TokenUtils.getClaimsFromJwt(request.getHeader("token"));
        Integer userId = (Integer) claims.get("id");
        Integer permission = (Integer) claims.get("permission");
        if (permission != 1) return CommonResult.userAuthError("用户未有权限");
        Integer integer = disabuseRecordMapper.selectCountByUserId(userId);
        if (integer == null) {
            integer = 0;
        }
        return CommonResult.success(String.valueOf(integer));
    }

    @Override
    public CommonResult<NoData> setVolunteerScore(VolunteerScoreParam volunteerScoreParam) {
        Integer i = volunteerScoreMapper.insert(volunteerScoreParam.getVolunteerId(), volunteerScoreParam.getScore(), volunteerScoreParam.getType());
        if(i==0){
            return CommonResult.fail("评分失败");
        }

        return CommonResult.success();

    }

    /**
     * 装载disabuseResult
     */
    private DisabuseResult setDisabuseResult(DisabuseRecord disabuseRecord) {
        DisabuseResult disabuseResult = new DisabuseResult();
        disabuseResult.setId(disabuseRecord.getId());
        disabuseResult.setName(userMapper.selectUserNameById(disabuseRecord.getChildId()));
        disabuseResult.setChildId(disabuseRecord.getChildId());
        disabuseResult.setQuestion(disabuseRecord.getQuestion());
        //处理type
        if (disabuseRecord.getType() == 1) {
            disabuseResult.setType("心理");
        } else if (disabuseRecord.getType() == 2) {
            disabuseResult.setType("学习");
        } else if (disabuseRecord.getType() == 3) {
            disabuseResult.setType("安全");
        } else if (disabuseRecord.getType() == 4) {
            disabuseResult.setType("生活");
        } else if (disabuseRecord.getType() == 5) {
            disabuseResult.setType("兴趣");
        } else if (disabuseRecord.getType() == 6) {
            disabuseResult.setType("感情");
        } else if (disabuseRecord.getType() == 7) {
            disabuseResult.setType("健康");
        }
        //处理solve_type
        if (disabuseRecord.getSolveType() == 1) {
            disabuseResult.setSolveType("线下");
        } else if (disabuseRecord.getSolveType() == 2) {
            disabuseResult.setSolveType("视频");
        } else if (disabuseRecord.getSolveType() == 3) {
            disabuseResult.setSolveType("语音");
        } else if (disabuseRecord.getSolveType() == 4) {
            disabuseResult.setSolveType("文字");
        }
        //处理是否匿名
        disabuseResult.setIsAnonymous(disabuseRecord.getIsAnonymous());
        //处理是否立即解决
        disabuseResult.setIsNowSolve(disabuseRecord.getIsNowSolve());
        //处理是否完成
        disabuseResult.setIsFinish(disabuseRecord.getIsFinish());
        disabuseResult.setTime(disabuseRecord.getTime());
        disabuseResult.setIsAccept(disabuseRecord.getIsAccept());
        //返回
        return disabuseResult;
    }
}

//class MyComparator implements Comparator<Map.Entry>{
//    public int compare(Map.Entry o1, Map.Entry o2) {
//    return ((String)o1.getValue()).compareTo((String)o2.getValue());
//    }
//}